<?php
namespace Admin\Controller;
use Think\Controller;
/**
* 门店管理
*/
class JubaoController extends AdminBasicController{
	public function _initialize(){
		$this -> jubaoview = M("Jubaoview");
		$this -> jubao = M("Jubao");
		$this -> Jpic = M("Jpic");
		$this -> relation = D("Relation");
		
	}

	public function jubaolist(){

		$name = $_POST['name'];
		$ctime = $_POST['ctime'];
		$status = $_POST['status'];
		if ( $name ) {
			$where['name'] = array('like',"%$name%");
		}
		if ( $ctime ) {
			$where['cctime'] = array('lt',$ctime);
		}
		$where['status'] = array('neq',9);
		if ( $status || $status == "0" ) {
			$where['status'] = $status;
		}
		$count = $this -> jubaoview ->where($where)->count();
        $page = new \Think\Page($count,15);
		$list = $this -> jubaoview ->limit($page->firstRow,$page->listRows) -> where($where) -> order('cctime desc') -> select();
		$this->assign('page',$page->show());
		$this->assign("list",$list);
		$this->display();
	}

	public function updjinfo(){
		$data['id'] = $_POST['id'];
		$data['name'] = $_POST['name'];
		$data['idcardno'] = $_POST['idcardno'];
		$data['tel'] = $_POST['tel'];
		$data['online'] = $_POST['online'];
		$data['area'] = $_POST['area'];
		$data['money'] = $_POST['money'];
		$data['ctime'] = $_POST['ctime'];
		$data['etime'] = $_POST['etime'];
		$data['remark'] = $_POST['remark'];

		$data1['id'] = $_POST['reid'];
		$data1['name'] = $_POST['llname'];
		$data1['relation'] = $_POST['llrelation'];
		$data1['tel'] = $_POST['lltel'];
		$data1['address'] = $_POST['lladdress'];

		$data['status'] = $_POST['status'];
		$data['year'] = date("Y",time());
		$data['datestr'] = date("d-m",time());
		$data['uid'] = session("userid");

		$pic = $_POST['pic'];

		$res = $this -> jubao -> save( $data );
		$data1['jid'] = $data['id'];
		$reldata = $this -> relation -> save($data1);
		apiResponse("success","举报成功！",$res);
	}

	public function findJubao(){
		$id = $_POST['id'];
		$ajaxdata = $this -> jubaoview -> where("id = $id") -> find();
		$pic = $this -> Jpic -> where("jid = $id") -> select();
		$ajaxdata['pic'] = $pic;
		if ( $ajaxdata ) {
			apiResponse("success","查询成功！",$ajaxdata);
		}else{
			apiResponse("error","数据获取失败！");
		}
	}

	public function expJub(){
		/**获取Excel导出数据*/
        $list = $this -> jubaoview -> Field('id,name,idcardno,tel,online,area,money,ctime,etime,remark,status,llname,relation,lltel,address,cctime') -> select();  
        /**查出来你要导出的数据*/
        
        $arrordername = array('ID号','名字','身份证','电话','失联','区域','借款金额','借款日期','结束日期','备注','状态','联系人','关系','联系人电话','联系人地址','创建时间');
        foreach($list as $key=>$val){
        	$val['status'] = $val['status'] == 1 ? '已发布' : $val['status'] == 4 ? '已撤销': '未发布' ;
            
            $arrorderlist[] = array($val['id'],$val['name'],$val['idcardno'],$val['tel'],$val['online'],$val['area'],$val['money'],$val['ctime'],$val['etime'],$val['remark'],$val['status'],$val['llname'],$val['relation'],$val['lltel'],$val['address'],$val['cctime']);
        }

        exportexcel($arrorderlist,$arrordername,'举报列表');
	}

	public function delju(){
		$id = $_POST['id'];
		$res = $this -> jubao -> where("id = $id") -> delete();
		if ( $res ) {
			apiResponse("success","删除成功！");
		}else{
			apiResponse("error","删除失败！");
		}
	}

	public function playdo(){
		$data['id'] = $_POST['id'];
		$data['status'] = 4;
		$res = $this -> jubao -> save($data);
		if ( $res ) {
			apiResponse("success","撤销成功！");
		}else{
			apiResponse("error","撤销失败！");
		}
	}
}